package com.sdp.refund.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.sdp.core.bizc.vo.Result;
import com.sdp.refund.db.refund_user.service.impl.RefundUserServiceImpl;
import com.sdp.refund.utils.RefundConstants;
import com.sdp.refund.view.RefundUserCountView;

import cn.hutool.json.JSONArray;

@RestController
@RequestMapping("/RefundAnalyzeController")
public class RefundAnalyzeController {
	
	@Autowired
	private RefundUserServiceImpl refundUserServiceImpl;

	@GetMapping(value = "/analyze")
	public Result<?> analyze() {
		List<RefundUserCountView> refundUserCountList = refundUserServiceImpl.selectRefundStateCount();
		JSONObject returnObj = new JSONObject();
		Map<String,String> refundStateMap = new HashMap<>();
		refundStateMap.put(RefundConstants.退费状态_未申请.getCode(), "未申请");
		refundStateMap.put(RefundConstants.退费状态_已申请.getCode(), "已申请");
		refundStateMap.put(RefundConstants.退费状态_已受理.getCode(), "已受理");
		refundStateMap.put(RefundConstants.退费状态_申请驳回.getCode(), "申请驳回");
		refundStateMap.put(RefundConstants.退费状态_已退费.getCode(), "已退费");
		
		//退费状态人员统计
		JSONArray refundStateCountArray = new JSONArray();
		JSONObject obj = null;
		for(RefundUserCountView user : refundUserCountList) {
			obj = new JSONObject();
			obj.put("name", refundStateMap.get(user.getRefundState()));
			obj.put("value", user.getCount());
			refundStateCountArray.add(obj);
		}
		
		returnObj.put("refundStateCountArray", refundStateCountArray);
		return Result.ok(returnObj);
	}
}
